import 'package:flutter/material.dart';
import 'package:flutter_ability/custom_ui.dart';
import 'package:flutter_ability_example/basis/button/button_page.dart';
import 'package:flutter_ability_example/basis/colos_a_page.dart';
import 'package:flutter_ability_example/basis/icon_page.dart';
import 'package:flutter_ability_example/basis/text/text_page.dart';
import 'package:flutter_ability_example/basis/toggle_page.dart';
import 'package:flutter_ability_example/utils/color_utils.dart';

class BasisPage extends StatefulWidget {
  const BasisPage({Key? key}) : super(key: key);

  @override
  State<BasisPage> createState() => _BasisPageState();
}

class _BasisPageState extends State<BasisPage> {
  List<String> mList = [
    "Font 字体",
    "Color 颜色",
    "Button 按钮",
    "Icon 图标",
    "Toggle 开关"
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("基础"),
      ),
      body: Container(
        padding: const EdgeInsets.only(left: 16, right: 16, top: 20),
        child: buildListView(),
      ),
    );
  }

  Widget buildListView() {
    return ListView.builder(
        itemCount: mList.length,
        scrollDirection: Axis.vertical,
        itemBuilder: (context, index) {
          return Row(
            children: [
              YJButton(
                size: YJSize.MEDIUM,
                onPressed: () {
                  Navigator.of(context).push(MaterialPageRoute(builder: (ctx) {
                    return openPage(index);
                    //return NewRoute("abc");
                  }));
                },
                text: mList[index],
                color: ColorUtils.getRandomColor(),
                textColor: Colors.white,
              ),
            ],
          );
        });
  }

  Widget openPage(int index) {
    if (index == 0) {
      return const TextPage();
    } else if (index == 1) {
      return const ColosAPage();
    } else if (index == 2) {
      return const ButtonPage();
    } else if (index == 3) {
      return const IconPage();
    } else if (index == 4) {
      return const TogglePage();
    } else {
      return const BasisPage();
    }
  }
}
